#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/ioctl.h>

#include "../ec_dev_inc/ec_dev_drv.h"
#include "../ec_dev_inc/run_status.h"

#define DBG_UART_PRT
//#include "dbg_prt.h"
#include "../ec_dev_inc/dbg_prt.h"


static EN_RUN_STATE_TYPE en_run_state;

static void disp_menu();

void disp_menu()
{
	dbg_prt_rn( "\n  3     read chip id for it8733" );
	#if 0
	dbg_prt_rn( "  4     start read cpu temperature and fan rpm" );
	dbg_prt_rn( "  5     start the thread read cpu temperature and fan rpm" );
	dbg_prt_rn( "  6     stop the thread read cpu temperature and fan rpm" );
	dbg_prt_rn( "  8     only once read cpu temperature and fan rpm" );
	dbg_prt_rn( "  u     the value of fan pwm +1" );

	dbg_prt_rn( "  d     the value of fan pwm -1" );
	#endif
	dbg_prt_rn( "  9     exit this program" );
}

int demo_it8733()
{	int ch;

	disp_menu();

	while(en_run_state!=RUN_STATE_EXIT)
    {
		ch = getchar();			/* If raw() hadn't been called
						 * we have to press enter before it
						 * gets to the program 		*/
		//if(ch == defKeyFMenuBgn+6 )		/* Without keypad enabled this will */
		//	printw("F7 Key pressed");/*  not get to us either	*/
						/* Without noecho() some ugly escape
						 * charachters might have been printed
						 * on screen			*/

		dbg_prt_rn( "en_run_state: %4d; ch=%d", en_run_state, ch );

		{
			if(ch == '3')
			{
				unsigned char chipid0;
				unsigned char chipid1;
				//CEcIt8733Rw::getInstance()->get_chip_id(&chipid0, &chipid1);
				//void dev_outb(int fd, unsigned char value, unsigned short int port)
				{
					typEcDev ecdev;
					//ecdev.port=port;
					//ecdev.value=value;
  					int fd=-1;
	
					fd = open("/dev/ec_it8733", O_RDWR);
					if (fd < 0)
					{
						dbg_prt_rn("can't open!\n");
					}
					ioctl(fd,EC_DEV_GET_CHIP_ID,&ecdev);

      				chipid0=ecdev.value;
      				chipid1=ecdev.port;
					close(fd);

				}
				
				dbg_prt_rn( "chipid0 =%02X; chipid1 =%02X",chipid0, chipid1 );


			}
			else if (ch == '4')
			{

			}

			else if (ch == 'u' || ch == 'U')
			{
			}		

			else if (ch == 'd'|| ch == 'D')
			{
			}			


			else if (ch == '8')
			{
			}		

			else if (ch == '9')
			{

				en_run_state=RUN_STATE_EXIT;
				dbg_prt_rn( "en_run_state: %4d ", en_run_state );
			}

			else if (ch == 10)  //enter
			{
				usleep(100*1000);
				disp_menu();

			}
			 

		}
	}

	return 0;
}

